import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/forget', component: () => import('@/views/login/resetpwd'), hidden: true },
  { path: '/register', component: () => import('@/views/register/index'), hidden: true },
  { path: '/edit/:userid', component: () => import('@/views/register/edit'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/home/index',
    name: 'index',
    hidden: true,
    children: [{
      path: 'home',
      component: () => import('@/views/home/index')
    }]
  },
  {
    path: '/home',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'home',
        component: () => import('@/views/home/index'),
        meta: { title: '首页', icon: 'home' }
      }
    ]
  }
]

export default new Router({
  // mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/advertising',
    component: Layout,
    name: 'advertising',
    children: [
      {
        path: 'index',
        name: 'advertising_index',
        component: () => import('@/views/advertising/index'),
        meta: { title: '新建广告', icon: 'ad' }
      }
    ]
  },
  {
    path: '/plan',
    component: Layout,
    name: 'plan',
    children: [
      {
        path: 'index',
        name: 'plan_index',
        component: () => import('@/views/plan/index'),
        meta: { title: '推广计划', icon: 'plan' }
      },
      {
        path: 'review/:ad_id',
        component: () => import('@/views/plan/review'),
        name: 'review',
        meta: { title: '审核推广计划' }, hidden: true
      },
      {
        path: 'view/:ad_id',
        component: () => import('@/views/plan/view'),
        name: 'view',
        meta: { title: '审核推广计划' }, hidden: true
      },
      {
        path: 'edit/:ad_id',
        component: () => import('@/views/plan/edit'),
        name: 'edit',
        meta: { title: '编辑推广计划' }, hidden: true
      }
    ]
  },
  {
    path: '/payment',
    component: Layout,
    name: 'payment',
    meta: { title: '财务管理', icon: 'payment' },
    children: [
      {
        path: 'recharge',
        name: 'recharge',
        component: () => import('@/views/payment/recharge'),
        meta: { title: '充值记录', icon: 'payment' }
      },
      {
        path: 'statistics',
        name: 'statistics',
        component: () => import('@/views/payment/statistics'),
        meta: { title: '充值统计', icon: 'expense' }
      },
      {
        path: 'expense',
        name: 'expense',
        component: () => import('@/views/payment/expense'),
        meta: { title: '消费记录', icon: 'expense' }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    name: 'user',
    children: [
      {
        path: 'index',
        name: 'user_index',
        component: () => import('@/views/user/index'),
        meta: { title: '用户管理', icon: 'people' }
      },
      {
        path: 'view/:userid',
        component: () => import('@/views/user/view'),
        name: 'view',
        meta: { title: '用户查看' }, hidden: true
      }
    ]
  },
  {
    path: '/permission',
    component: Layout,
    name: 'permission',
    meta: { title: '权限管理', icon: 'permission' },
    children: [
      {
        path: 'group',
        name: 'group',
        component: () => import('@/views/permission/grouplist'),
        meta: { title: '用户组列表', icon: 'group' }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/permission/role'),
        meta: { title: '角色列表', icon: 'role' }
      },
      {
        path: 'node',
        name: 'node',
        component: () => import('@/views/permission/nodes'),
        meta: { title: '权限组列表', icon: 'permission' }
      },
      {
        path: 'authallocate/:role_id',
        name: 'authallocate',
        component: () => import('@/views/permission/authallocate'),
        meta: { title: '权限分配' }, hidden: true
      }
    ]
  },
  {
    path: '/other',
    component: Layout,
    name: 'other',
    meta: { title: '辅助功能', icon: 'example' },
    children: [
      {
        path: 'position',
        name: 'position',
        component: () => import('@/views/other/position'),
        meta: { title: '广告位版位', icon: 'example' }
      },
      {
        path: 'ad_type',
        name: 'ad_type',
        component: () => import('@/views/other/ad_type'),
        meta: { title: '广告类型', icon: 'example' }
      },
      {
        path: 'tags',
        name: 'tags',
        component: () => import('@/views/other/tags'),
        meta: { title: '用户标签', icon: 'example' }
      }
    ]
  },
  { path: '*', name: '404', redirect: '/404', hidden: true }
]

